package com.bulls.demo.hrmsdemo.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import com.bulls.demo.hrmsdemo.db.Person;
import com.bulls.demo.hrmsdemo.db.User;

public class SignupDAOImpl implements SignupDAO{

	@Override
	public Person save(Person person, EntityManager entityManager) {
		try{
			EntityTransaction trans = entityManager.getTransaction();
			trans.begin();
			if(person.getPersonsk()!=0){
			entityManager.merge(person);
		}else{
			entityManager.persist(person);
			
		}
			trans.commit();
	}
	catch(Exception e){
		e.printStackTrace();
	}
	return person;
	}

	@Override
	public User save(User user, EntityManager entityManager) {
		EntityTransaction trans = entityManager.getTransaction();
		trans.begin();
		if(user.getUserid()!=null && user.getUserid()!=0){
			entityManager.merge(user);
		}else{
			entityManager.persist(user);
		}
		trans.commit();
		return user;
	}
}
